package cn.java76.springboot.demo1.controller;

import cn.java76.springboot.demo1.es.NewsService;
import cn.java76.springboot.demo1.vo.News;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.index.Indexed;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
@RestController

public class NewsController {

    @Autowired
    private NewsService newsService;

    @GetMapping("newsearch")
    public List<News> search() {
        MatchAllQueryBuilder queryBuilder = QueryBuilders.matchAllQuery();

        List<News> resultList = new ArrayList<>();
        Iterable<News> search = this.newsService.search(queryBuilder);
        search.forEach(resultList::add);
        return resultList;
    }


}
